﻿/*----------------------------------------------------------------------------------------
*
*  Copyright 2019, Gao Hai Hui, <fromzeropoint@126.com>.  All rights reserved.
*  https://gitee.com/helloworldghh/xoskit.git
*  Use of this source code is governed by a MIT license
*  that can be found in the License file.
*
----------------------------------------------------------------------------------------*/
#ifndef __XOS_COMMON_SRC_OBJECTS_MEM_ALLOC_H__
#define __XOS_COMMON_SRC_OBJECTS_MEM_ALLOC_H__

#include "../tools/head.h"

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

namespace xos_common
{

	// 
	// 内存分配类
	// 
	class mem_alloc : public xos_stl::mem_item< xos::release_impl< mem_alloc >, thread_lock >,
		public i_alloc
	{
    public:
        typedef xos::release_impl< mem_alloc > T;

    public:
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //

        static int get_addr( POOL *** pppPool, LIST *** pppList );

    public:
		mem_alloc();
		~mem_alloc();

	protected:
		int m_nPropSize;

	public:
		int init();
		int term();

	protected:
		void * malloc_from_big_buf( int nSize );
		void * malloc_from_small_buf( int nSize );
		void * malloc_from_memory( int nSize );

	public:
		void * my_malloc( size_t size );
		void my_free( void *address );
	};
}

#endif // __XOS_COMMON_SRC_OBJECTS_MEM_ALLOC_H__
